/*----------------------------------------------------------------------------
* This unit test tests the smithy card effect. 
* Randomness is not working need to figure out why. 
*----------------------------------------------------------------------------*/
#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <time.h>

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 0

int testSmithy(int currentPlayer, struct gameState *state)
{
	int handCount1, handPos, check, choice1, choice2, choice3;
	struct gameState preG;	

	//handCount before smithy 
	handCount1 = state->handCount[currentPlayer];
#if (NOISY_TEST == 1)
	printf("\t Details: handCount before = %d.", handCount1);
#endif	

	handPos = floor(Random() * state->handCount[currentPlayer]);

	memcpy(&preG, state, sizeof(struct gameState));

	choice1 = floor(Random() * 256);
	choice2 = floor(Random() * 256);
	choice3 = floor(Random() * 256);
	check = cardEffect(smithy, choice1, choice2, choice3, state, handPos, 0);

	//+3 Cards
	int i;
	for (i = 0; i < 3; i++)
	{
		drawCard(currentPlayer, &preG);
	}

	//discard card
	discardCard(handPos, currentPlayer, &preG, 0);

	if(check != 0)
		printf("smith card effect: FAIL. \n");		
	
	if(memcmp(&preG, state, sizeof(struct gameState)) != 0)
		printf("smith card effect: FAIL. \n");	
		
	if(state->handCount[currentPlayer] != handCount1 + 2);
		printf("smith card effect: FAIL. \n");	

#if (NOISY_TEST == 1)
	printf("handCount after = %d. \n", state->handCount[currentPlayer]);
#endif	

	return 0;
}

int main()
{
	int i, j, p, seed, numTests = 50;
	struct gameState G;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
			   
	printf("TESTING smithy card effect:\n");

	for (i = 0; i < numTests; i++)
	{		

		//clear game state
		for (j = 0; j < sizeof(struct gameState); j++)
		{
			((char*)&G)[j] = floor(Random() * 256);
		}
		
		srand(time(NULL));
		seed = rand() % 10;
		
 		//initialize game		
		SelectStream(seed);
		PutSeed((long)seed);
		initializeGame(MAX_PLAYERS, k, 3, &G); 
	
		
		//fill values with Random()
		p = (int)floor(Random() * MAX_PLAYERS);		
		G.whoseTurn = p;
		G.handCount[p] = (int)floor(Random() * MAX_HAND);
		SelectStream(2);
		G.deckCount[p] = (int)floor(Random() * MAX_DECK);
		SelectStream(4);
		G.discardCount[p] = (int)floor(Random() * MAX_DECK);
		SelectStream(3);
		G.playedCardCount = (int)floor(Random() * MAX_DECK);

		//Test our smthy card function/card Effect case.
		testSmithy(p, &G); 
	}

	printf("smithy card effect: PASS. \n");

	return 0;
}
